package aconcagua.measure

class DividedUnit extends CompoundUnit {
	private numerator;
	private denominator;

	// (class) instance creation
	public DividedUnit(aUnit, anotherUnit) {
		numerator = aUnit;
		denominator = anotherUnit;
	}

	// accessing
	@Override
	public denominator() {
		return denominator;
	}

	@Override
	public nameForMany() {
		return numerator.nameForMany() +'/'+ denominator.nameForMany();
	}

	@Override
	public nameForOne() {
		return numerator.nameForOne() +'/'+ denominator.nameForOne();
	}

	@Override
	public numerator() {
		return numerator;
	}

	@Override
	public sign() {
		return numerator.sign() +'/'+ denominator.sign();
	}

	// arithmetic operations
	@Override
	public divideByUnit(aUnit) {
		return aUnit.divide(this);
	}

	@Override
	public multiplyByUnit(aUnit) {
		return aUnit.multiply(this);
	}

	// arithmetic operations - private
	@Override
	protected divide(DividedUnit aUnit) {
		return new DividedUnit(this, aUnit);
	}

	@Override
	protected divide(MultipliedUnit aUnit) {
		return new DividedUnit(this, aUnit);
	}

	@Override
	protected divide(NullUnit aUnit) {
		return new DividedUnit(aUnit, this);
	}

	@Override
	protected divide(SimpleUnit aUnit) {
		return new DividedUnit(this, aUnit);
	}

	@Override
	protected multiply(DividedUnit aUnit) {
		return new MultipliedUnit(aUnit, this);
	}

	@Override
	protected multiply(MultipliedUnit aUnit) {
		return new MultipliedUnit(aUnit, this);
	}

	@Override
	protected multiply(NullUnit aUnit) {
		return new MultipliedUnit(aUnit, this);;
	}

	@Override
	protected multiply(SimpleUnit aUnit) {
		return new MultipliedUnit(aUnit, this);
	}

	// comparing
	@Override
	public boolean equals(Object anObject) {
		return (this.getClass() == anObject.getClass()
		&& numerator == anObject.numerator()
		&& denominator == anObject.denominator());
	}

	@Override
	public int hashCode() {
		return numerator.hashCode().xor(denominator.hashCode());
	}
}
